Data Tree Document
The data document is used to manipulate a data tree
Expected common APIs
The system should be able to
- Parse
- ToText/Stringify
- findAtPath
Intermediate Representation
A data tree and all this nodes are owned by an document object (see [aDataDocument
](../../4. Reference/aDataDocument)), the node are defined by the class [aDataValue
](../../4. Reference/aDataValue).
aDataValue
is an object which can become different kind of data:
map
: is a key-value collection (with a classname metadata)array
: is a value liststring
number
integer
undefined
All data tree nodes in a document are destroyed when the document is destroyed.
Manual Tree Creation
var data: aDataDocument
var txt: Text
new(data)
data.Map('keyA').SetCString('valueA')
data.Map('keyB').Map('keyB1').SetInt(42)
data.Map('keyB').Map('keyB2').SetNum(42.42)
data.SetIndent(true)
; Stringify in JSON
if Doc.JSON.StringifyText(data, text)
endIf
write(txt)
txt:=''
Expected output:
{
"keyA": "valueA",
"keyB": {
"keyB1": 42,
"keyB2": 42.42
}
}
Parsing JSON
The parser supports trailing comas and comments. For example:
{
//User name
"Name": "Nicolas",
/*
User age
Age has a trailing coma
*/
"Age": 38,
}
Will be parsed successfully with a code like this:
var bytes : Text
var content : aDataDocument
var config : aDataValue
; Read config file
new(content)
content.SetClassNameProperty('className')
bytes.type.LoadFromFile('(wyde-admin)/config-tech.json', @bytes)
if content.Parse(bytes)
endIf
bytes := ''
;
config = content.CreateValue
Note: the data document (content in the previous example) should be disposed after used as we instanciated it using new. But data values retreives from a data document (using Find, Get, ... method) don't need to be disposed as they are handled by the data document.